const state = {
  //模板列表
  templateMana: [],
  //步骤管理列表
  stepManagement: [],
  //审批人列表：
  approverList: [
    {
      depName: "泌尿科",
      name: "朱丽叶",
      yhName: "juliet",
      role: "秘书",
      tel: "15868886888",
    },
    {
      depName: "肿瘤科",
      name: "罗密欧",
      yhName: "romeo",
      role: "院长",
      tel: "18600186000",
    },
    {
      depName: "总医院",
      name: "盖茨",
      yhName: "admin",
      role: "超级管理员",
      tel: "13800138000",
    },
  ],
};

const actions = {
  addTemManaSave(context, row) {
    context.commit("addTemManaSave", row);
  },
  reviseTemManaSave(context, row) {
    context.commit("reviseTemManaSave", row);
  },
  deleteTemMana(context, row) {
    context.commit("deleteTemMana", row);
  },
  newTempSave(context, row) {
    context.commit("newTempSave", row);
  },
  stepSave(context, row) {
    context.commit("stepSave", row);
  },
};

const getters = {};

const mutations = {
  addTemManaSave(state, row) {
    state.templateMana.push(row);
    for (let i = 0; i < state.templateMana.length; i++) {
      state.templateMana[i].id = i;
      for (let j = 0; j < state.templateMana[i].children.length; j++) {
        state.templateMana[i].children[j].id = state.templateMana.length + 10;
      }
    }
  },
  reviseTemManaSave(state, row) {
    for (let i = 0; i < state.templateMana.length; i++) {
      if (row.id == state.templateMana[i].id) {
        state.templateMana[i].name = row.name;
        state.templateMana[i].display = row.display;
      }
    }
  },
  deleteTemMana(state, row) {
    for (let i = 0; i < state.templateMana.length; i++) {
      if (row == state.templateMana[i].id) {
        state.templateMana.splice(i, 1);
      }
      for (let j = 0; j < state.templateMana[i].children.length; j++) {
        state.templateMana[i].children[j].id = state.templateMana.length + 10;
        if (row == state.templateMana[i].children[j].id) {
          state.templateMana[i].children.splice(j, 1);
        }
      }
    }
  },
  newTempSave(state, row) {
    for (let i = 0; i < state.templateMana.length; i++) {
      if (row.fatherId == state.templateMana[i].id) {
        state.templateMana[i].children.push(row);
      }
      for (let j = 0; j < state.templateMana[i].children.length; j++) {
        state.templateMana[i].children[j].id = state.templateMana.length + 10;
      }
    }
  },
  stepSave(state, row){
    state.stepManagement.push(row)
    for (let i = 0; i < state.stepManagement.length; i++) {
      state.stepManagement[i].id = i;
    }
  }
};

export default {
  state,
  mutations,
  actions,
  getters,
};
